<!--
 * @Author: 赖钊亮
 * @Description: 我的收藏界面
 * @Date: 2020-07-02 12:49:20
 * @LastEditTime: 2020-07-06 17:51:19
 * @LastEditors: Please set LastEditors
 * @FilePath: \mobile_item_121f:\JK\jkshopping\src\pages\my\components\collection.vue
--> 
<template>
  <div>
    <!--我的积分顶部 -->
    <van-nav-bar title="我的收藏" left-text="返回" left-arrow @click-left="goBack" />

    <div class="collection">
      <template v-if="datas.length">
        <van-grid :border="true" :gutter="10" :column-num="2">
          <van-grid-item v-for="(item,idx) of datas" :key="idx">
            <router-link :to="{path:'/goodsDetails',query:{id:item.goods.id}}">
              <div class="img">
                {{item.goods.goods_name}}
                <van-image height="100%" lazy-load :src="item.goods.goods_thumb" />
              </div>
              <div>
                <p class="goods_name">{{item.goods.goods_name}}</p>
                <div class="price clearFix">
                  <p>{{item.goods.min_price | rmb}}</p>
                  <van-icon name="like" />
                </div>
                <div class="comment">
                  <p>35个评价&nbsp;&nbsp;98%好评</p>
                  <!-- <p>{{item.collection_count}}</p> -->
                </div>
              </div>
            </router-link>
          </van-grid-item>
        </van-grid>
      </template>

      <template v-else>
      <div class="NO">
      <van-sticky :offset-top="300">
         <p>暂无商品</p> 
        </van-sticky>
      </div>
        
      </template>
    </div>
  </div>
</template>

<script>
import * as api from "@/api/apiList/user/collect/collect.js";
export default {
  data() {
    return {
      datas: [] //收藏列表数据
    };
  },
  methods: {
    // 收藏列表接口
    async API_collect() {
      return await api.collect();
    },
    // 返回上一页
    goBack() {
      this.$router.go(-1);
    }
  },
  async created() {
    // 收藏列表
    let res = await this.API_collect();
    console.log(res);

    if (res.data.code === 200) {
      this.datas = res.data.data.data;
      // console.log(this.datas);
    }
  }
};
</script>

<style lang="scss" scoped>
//热销
.hotSale {
  background: #f4f4f4;
  h1 {
    display: flex;
    align-items: center;
    padding: 20px 0;
    justify-content: center;
  }
  .van-grid {
    .img {
      height: 250px;
    }
    .goods_name {
      color: #000;
    }
    p {
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2; //这里设置显示文本行数
      overflow: hidden;
    }
    .price {
      margin: 10px 0;
      p {
        color: #ff7882;
        float: left;
        font-weight: bold;
      }
      .van-icon {
        font-size: 20px;
        color: #dddddd;
        float: right;
      }
    }

    .comment {
      p {
        font-size: 10px;
        color: #dddddd;
      }
    }
  }
}
.NO {
  text-align: center;
  display: block;
  margin: 0 auto;
  height: 50%;
  p{
    font-size: 30px;
  }
}
</style>